package Chapter9;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Example21 extends JFrame{
	private JComboBox combomBox;
	private JTextField field;
	public Example21() {
		JPanel panel=new JPanel();
		combomBox=new JComboBox();
		combomBox.addItem("请选择城市");
		combomBox.addItem("北京");
		combomBox.addItem("上海");
		combomBox.addItem("南京");
		combomBox.addItem("重庆");
		combomBox.addItem("天津");
		combomBox.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String item=(String) combomBox.getSelectedItem()	;
				if("请选择城市".equals(item)) {
					field.setText("");
				}else {
					field.setText("Your chioce is "+item);
				}
			}
		});
		field=new JTextField(20);
		panel.add(combomBox);
		panel.add(field);
		this.add(panel, BorderLayout.NORTH);
		this.setSize(350,100);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
	}
	public static void main(String[] args) {
		new Example21();
	}
}
